#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more 
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership. 
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with 
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion


using System;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace IPSim.GUI.Devices
{
    /// <author>Edward Smit</author>
    public class StraightLinkDevice : BaseLinkDevice, IControllable
    {
        #region Members

        protected LineDevice lineDevice = new LineDevice(0, 0, 0, 0);

        private LineController controller;

        #endregion

        #region Methods

        internal StraightLinkDevice(ConnectorDevice conn1, ConnectorDevice conn2)
            : base(conn1, conn2)
		{
            CalcLink();
		}

        internal override void Draw(System.Drawing.Graphics g)
        {
            CalcLink();
            lineDevice.Draw(g);
        }

        internal override void CalcLink()
        {
            if (lineDevice != null)
            {
                Point connector1Location = connector1.Location;
                Point connector2Location = connector2.Location;
                Size connector1Size = connector1.Size;
                Size connector2Size = connector2.Size;

                lineDevice.StartPoint = new Point(connector1Location.X + connector1Size.Width / 2, connector1Location.Y + connector1Size.Height / 2);
                lineDevice.EndPoint = new Point(connector2Location.X + connector2Size.Width / 2, connector2Location.Y + connector2Size.Height / 2);
                lineDevice.CalcLine();
            }
        }

        IController IControllable.GetController()
        {
            if (controller == null)
                controller = new LineController(lineDevice);
            return controller;
        }

        #endregion

        #region Properties

        public override Point Location
        {
            get { CalcLink(); return lineDevice.Location; }
        }

        public override Size Size
        {
            get { CalcLink(); return lineDevice.Size; }
        }

        public override Point StartPoint
        {
            get { return lineDevice.StartPoint; }
        }

        public override Point EndPoint
        {
            get { return lineDevice.EndPoint; }
        }

        #endregion

        #region Events


        #endregion

    }
}
